package com.ruoyi.web.controller.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.BasisGroundEnvironment;
import com.ruoyi.service.IBasisGroundEnvironmentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 阵地环境Controller
 * 
 * @author wangzebing
 * @date 2025-05-11
 */
@RestController
@RequestMapping("/groundenvironment")
public class BasisGroundEnvironmentController extends BaseController
{
    @Autowired
    private IBasisGroundEnvironmentService basisGroundEnvironmentService;

    /**
     * 查询阵地环境列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasisGroundEnvironment basisGroundEnvironment)
    {
        startPage();
        List<BasisGroundEnvironment> list = basisGroundEnvironmentService.selectBasisGroundEnvironmentList(basisGroundEnvironment);
        return getDataTable(list);
    }

    //查询全部阵地数据
    @GetMapping("/findAllBasisGroundEnvironmentList")
    public AjaxResult findAllBasisGroundEnvironmentList()
    {
        List<BasisGroundEnvironment> list = basisGroundEnvironmentService.findAllBasisGroundEnvironmentList(new BasisGroundEnvironment());
        return success(list);
    }

    /**
     * 导出阵地环境列表
     */
    @Log(title = "阵地环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasisGroundEnvironment basisGroundEnvironment)
    {
        List<BasisGroundEnvironment> list = basisGroundEnvironmentService.selectBasisGroundEnvironmentList(basisGroundEnvironment);
        ExcelUtil<BasisGroundEnvironment> util = new ExcelUtil<BasisGroundEnvironment>(BasisGroundEnvironment.class);
        util.exportExcel(response, list, "阵地环境数据");
    }

    /**
     * 获取阵地环境详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basisGroundEnvironmentService.selectBasisGroundEnvironmentById(id));
    }

    /**
     * 新增阵地环境
     */
    @Log(title = "阵地环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasisGroundEnvironment basisGroundEnvironment)
    {
        basisGroundEnvironment.setType("阵地");
        return toAjax(basisGroundEnvironmentService.insertBasisGroundEnvironment(basisGroundEnvironment));
    }

    /**
     * 修改阵地环境
     */
    @Log(title = "阵地环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasisGroundEnvironment basisGroundEnvironment)
    {
        return toAjax(basisGroundEnvironmentService.updateBasisGroundEnvironment(basisGroundEnvironment));
    }

    /**
     * 删除阵地环境
     */
    @Log(title = "阵地环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(Long[] ids,String loadingId)
    {
        return toAjax(basisGroundEnvironmentService.deleteBasisGroundEnvironmentByIds(ids,loadingId));
    }
}
